package com.btex.app;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.btex.app.adapter.MyFragmentAdapter;
import com.btex.app.adapter.TradesAdapter;
import com.btex.app.entity.BtexInfo;
import com.btex.app.entity.FuturesInfo;
import com.btex.app.entity.TradeInfo;
import com.btex.app.kine.kline.KData;
import com.btex.app.kine.kline.NewKLineView;
import com.btex.app.tools.DensityUtil;
import com.btex.app.tools.MicroAVLIDialog;
import com.btex.app.tools.Tools;
import com.btex.app.treaty.ChengJiaoFragment;
import com.btex.app.treaty.MyViewPager;
import com.btex.app.treaty.WeiTuoFragment;
import com.google.gson.Gson;
import com.guoziwei.klinelib.chart.KLineView;
import com.guoziwei.klinelib.model.HisData;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FuturesKLineActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_menu)
    TextView mTvMenu;
    @BindView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @BindView(R.id.activity_b_k_name)
    TextView mActivityBKName;
    @BindView(R.id.activity_b_k_money)
    TextView mActivityBKMoney;
    @BindView(R.id.activity_b_k_rise)
    TextView mActivityBKRise;
    @BindView(R.id.activity_b_k_height)
    TextView mActivityBKHeight;
    @BindView(R.id.activity_b_k_vol)
    TextView mActivityBKVol;
    @BindView(R.id.activity_b_k_lowest)
    TextView mActivityBKLowest;
    @BindView(R.id.activity_b_k_shaixuan)
    ImageView mActivityBKShaixuan;
    @BindView(R.id.activity_b_k_full)
    ImageView mActivityBKFull;
    @BindView(R.id.activity_kine_k)
    KLineView mKLineView;
    @BindView(R.id.activity_recy_k)
    RecyclerView mActivityRecyK;
    @BindView(R.id.ll_shidang)
    LinearLayout mLlShidang;
    @BindView(R.id.activity_k_time)
    TextView mActivityKTime;
    @BindView(R.id.activity_b_k_full_tv)
    TextView mActivityBKFullTv;
    @BindView(R.id.activity_kline_zhi_biao)
    TextView mActivityKlineZhiBiao;
    @BindView(R.id.tv_otc_la)
    ImageView mTvOtcLa;
    @BindView(R.id.kine_activity_five)
    TextView mKineActivityFive;
    @BindView(R.id.kine_activity_fifteen)
    TextView mKineActivityFifteen;
    @BindView(R.id.kine_activity_one_hours)
    TextView mKineActivityOneHours;
    @BindView(R.id.kine_activity_one_day)
    TextView mKineActivityOneDay;
    @BindView(R.id.kine_activity_full)
    TextView mKineActivityFull;
    @BindView(R.id.kine_activity_thirty)
    TextView mKineActivityThirty;
    @BindView(R.id.activity_futures_full)
    LinearLayout mActivityFuturesFull;
    @BindView(R.id.activity_k_viewpager)
    MyViewPager mActivityKViewpager;
    @BindView(R.id.treaty_tv_weituo)
    TextView mTreatyTvWeituo;
    @BindView(R.id.treaty_tv_zuixin_chengiao)
    TextView mTreatyTvZuixinChengiao;

    @BindView(R.id.activity_k_heli)
    TextView activity_k_heli;

    @BindView(R.id.activity_kine_24)
    TextView activity_kine_24;
    @BindView(R.id.activity_mairu)
    Button mActivityMairu;
    @BindView(R.id.activity_maichu)
    Button mActivityMaichu;
    @BindView(R.id.K_xian_lin)
    LinearLayout mKXianLin;
    @BindView(R.id.activity_lin_ci_cang_liang)
    TextView mActivityLinCiCangLiang;
    private List<HisData> mHisDatas;
    private String mPair;
    private Object mListInfo;

    private TradesAdapter mTradesAdapter;
    private MicroAVLIDialog mMicroAVLIDialog;
    public boolean isShow;
    private TextView mPop_clssify_types_d;
    public boolean isActivityShow;
    public boolean isShowKdj;

    public String times = "5";
    private NewKLineView mKineview;
    public int size = 0;

    public boolean isRefresh = false;
    public String mContract_id;

    public double old = 0;
    public String mPrice_float_num;
    public String mSa_float_num;
    public String mContract_anchor;
    public String activitytype = "2";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kline);
        ButterKnife.bind(this);
        mTreatyTvWeituo.setSelected(true);

        mRlTitle.setBackgroundResource(R.color.FuturesKLineActivity_color);
        mIvBack.setBackgroundResource(R.color.FuturesKLineActivity_color);
        mKineActivityFive.setSelected(true);
        initListener();
        mKineview = (NewKLineView) findViewById(R.id.new_kine_view);
        mKineview.setCrossHairMoveMode(2);

        mKineview.setOnRequestDataListListener(new NewKLineView.OnRequestDataListListener() {
            @Override
            public void requestData() {

            }
        });

        mActivityRecyK.setNestedScrollingEnabled(false);
        mPair = (String) getIntent().getExtras().get("pair");

        mContract_id = (String) getIntent().getExtras().get("contract_id");

        if (!TextUtils.isEmpty(mPair)) {
            String[] split = mPair.split("_");
            String s = split[0];
            String s1 = split[1];
            mTvTitle.setText(s + "/" + s1);
            mActivityBKName.setText(s + "/" + s1);
        }


        mMicroAVLIDialog = new MicroAVLIDialog(this);
        mMicroAVLIDialog.setCanceledOnTouchOutside(true);
        mMicroAVLIDialog.show();
        initRecyClerview();
        getMxCcontracts(mContract_id);
        geTexchangeRate();
        getListInfo();
        initData();
        initInfo("1m");

        initOnclik();
        double d = 88.88;
        long l = Math.round(d);


    }

    private void initViewPager() {
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new WeiTuoFragment());
        fragments.add(new ChengJiaoFragment());

        ArrayList<String> strings = new ArrayList<>();
        strings.add("历史委托");
        strings.add("已成交");
        strings.add("已平仓位");
        mActivityKViewpager.setAdapter(new MyFragmentAdapter(getSupportFragmentManager(), fragments, strings));
        mActivityKViewpager.setOffscreenPageLimit(2);
        mActivityKViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                if (position == 0) {
                    mTreatyTvWeituo.setSelected(true);
                    mTreatyTvZuixinChengiao.setSelected(false);
                } else {
                    mTreatyTvWeituo.setSelected(false);
                    mTreatyTvZuixinChengiao.setSelected(true);
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {


            }
        });
    }

    private void initListener() {


        mActivityMairu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mActivityMaichu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        //        5分
        mKineActivityFive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mKineActivityFull.setText("更多");
                size = 0;

                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }
                times = "1";
                setStat();
                mKineActivityFive.setSelected(true);
                initInfo("1m");
            }
        });

//        15分
        mKineActivityFifteen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "15";
                setStat();
                mKineActivityFifteen.setSelected(true);
                initInfo("15m");
            }
        });

        mKineActivityThirty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "30";
                setStat();
                mKineActivityThirty.setSelected(true);
                initInfo("30m");
            }
        });

//        1小时
        mKineActivityOneHours.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "1h";
                setStat();
                mKineActivityOneHours.setSelected(true);
                initInfo("1h");
            }
        });

//        一天

        mKineActivityOneDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "4h";
                setStat();
                mKineActivityOneDay.setSelected(true);
                initInfo("4h");
            }
        });


    }


    private void setStat() {
        mKineActivityOneDay.setSelected(false);
        mKineActivityOneHours.setSelected(false);
        mKineActivityFifteen.setSelected(false);
        mKineActivityFive.setSelected(false);
        mKineActivityThirty.setSelected(false);
        mKineActivityFull.setSelected(false);
    }


    private void initOnclik() {


        mKineActivityFull.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                setStat();
                mKineActivityFull.setSelected(true);
                View contentView = View.inflate(cxt, R.layout.pop_kline, null);


                TextView pop_new_k_1_day = (TextView) contentView.findViewById(R.id.pop_new_k_1_day);
                TextView pop_new_k_1_week = (TextView) contentView.findViewById(R.id.pop_new_k_1_week);
                TextView pop_new_k_30 = (TextView) contentView.findViewById(R.id.pop_new_k_30);
                TextView pop_new_k_5 = (TextView) contentView.findViewById(R.id.pop_new_k_5);


                //获取屏幕宽高
                DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
                //屏幕宽
                int widthPixels = displayMetrics.widthPixels;
                //屏幕高
                int heightPixels = displayMetrics.heightPixels;

                final PopupWindow pop = new PopupWindow(contentView, widthPixels, 100);
                int[] location = new int[2];
                v.getLocationInWindow(location);
                pop.setOutsideTouchable(true);
                pop.setBackgroundDrawable(cxt.getResources().getDrawable(R.color.transparent));

                pop.showAtLocation(mKXianLin, Gravity.CENTER | Gravity.TOP, DensityUtil.dip2px(cxt, 72), location[1] + DensityUtil.dip2px(cxt, 30));
                pop_new_k_1_day.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("1天");
                        times = "1d";
                        initInfo("1d");
                        pop.dismiss();
                    }
                });


                pop_new_k_1_week.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("1周");
                        times = "1w";
                        initInfo("1m");

                        pop.dismiss();
                    }
                });


                pop_new_k_30.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("30分");
                        times = "30";
                        initInfo("30m");
                        pop.dismiss();

                    }
                });


                pop_new_k_5.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("5分");
                        times = "5";
                        initInfo("5m");
                        pop.dismiss();

                    }
                });

            }
        });


        mTreatyTvWeituo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivityKViewpager.setCurrentItem(0);
            }
        });

        mTreatyTvZuixinChengiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivityKViewpager.setCurrentItem(1);
            }
        });


        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void initRecyClerview() {

        mActivityRecyK.setLayoutManager(new LinearLayoutManager(this));
        mTradesAdapter = new TradesAdapter(null);
    }

    @Override
    public void setData() {


    }

    @Override
    public void onClick(View view) {

    }


    private void initInfo(String time) {

        int numtest = (int) ((Math.random() * 9 + 1) * 100000);

        OkGo.<String>get(Config.K_DATA + "?rnd=" + String.valueOf(numtest)).tag(this).params("limit", "300").params("type", time).params("symbol", mContract_id).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {

                Log.i("wkeuhfiwuhefiuwhefiuwhe", String.valueOf(response.body()));

                String result = response.body().toString();

                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.dismiss();
                }
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if (jsonObject.getString("code").equals("1")) {
                        setKineData(result);
                    } else {

                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });


//        Log.i("wefjwoeif", "type===" + time + "symbol=======" + mPair);
//        RequestParams params = new RequestParams();
//        params.addQueryStringParameter("limit", "300");
//        params.addQueryStringParameter("type", time);
//        params.addQueryStringParameter("symbol", mContract_id);
//        int num = (int) ((Math.random() * 9 + 1) * 100000);
//
//        HttpHandler<String> send = new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.K_DATA + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                Log.i("wkejfkweufhwiefhu", responseInfo.result);
//
//                if (mMicroAVLIDialog != null) {
//                    mMicroAVLIDialog.dismiss();
//                }
//                try {
//                    JSONObject jsonObject = new JSONObject(responseInfo.result);
//                    if (jsonObject.getString("code").equals("1")) {
//                        setKineData(responseInfo.result);
//                    } else {
//
//                    }
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//                mMicroAVLIDialog.dismiss();
//                Toast.makeText(cxt, msg, Toast.LENGTH_SHORT).show();
//
//            }
//        });

    }


    public void getListInfo() {
        int num = (int) ((Math.random() * 9 + 1) * 100000);

        OkGo.<String>get(Config.TRADES + "?rnd=" + String.valueOf(num)).tag(this).params("contract_id", mContract_id).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {

                String result = response.body().toString();


                try {
                    JSONObject jsonObject = new JSONObject(result);

                    if (jsonObject.getString("code").equals("1")) {

                        Gson gson = new Gson();
                        TradeInfo tradeInfo = gson.fromJson(result, TradeInfo.class);
                        List<TradeInfo.DataBean.ListBean> list = tradeInfo.getData().getList();
                        mActivityRecyK.setAdapter(mTradesAdapter);
                        mTradesAdapter.SetTyee("1");
                        mTradesAdapter.setNewData(list);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();

                }

            }
        });


//        RequestParams params = new RequestParams();
//        params.addQueryStringParameter("contract_id", mContract_id);
//
//        new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.TRADES + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                Log.i("lwefjwjefoiwe", responseInfo.result);
//
//                try {
//                    JSONObject jsonObject = new JSONObject(responseInfo.result);
//
//                    if (jsonObject.getString("code").equals("1")) {
//
//                        String result = responseInfo.result;
//                        Gson gson = new Gson();
//                        TradeInfo tradeInfo = gson.fromJson(result, TradeInfo.class);
//                        List<TradeInfo.DataBean.ListBean> list = tradeInfo.getData().getList();
//                        mActivityRecyK.setAdapter(mTradesAdapter);
//                        mTradesAdapter.SetTyee("1");
//                        mTradesAdapter.setNewData(list);
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//
//            }
//        });
    }


    private void geTexchangeRate() {

        int num = (int) ((Math.random() * 9 + 1) * 100000);


        OkGo.<String>get(Config.GET_MX_CONTRACTS + "?rnd=" + String.valueOf(num)).tag(this).params("contract_id", mContract_id).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {

                String result = response.body().toString();
                Log.i("wliefhowiefwji", result);

                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {
                        setTexchangeRate(result);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();

                }
            }
        });


//        RequestParams params = new RequestParams();
//        params.addQueryStringParameter("contract_id", mContract_id);
//
//        new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.GET_MX_CONTRACTS + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                String result = responseInfo.result;
//                Log.i("sjeuwyeuwye", responseInfo.result);
//                try {
//                    JSONObject jsonObject = new JSONObject(result);
//                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {
//
//
//                        setTexchangeRate(responseInfo.result);
//
//
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//
//                }
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//            }
//        });
    }

    private void setTexchangeRate(String result) {
//        mActivityBKHeight.setText(texchangeRateInfo.getData().getHigh());
//                        mActivityBKLowest.setText(texchangeRateInfo.getData().getLow());
//                        mActivityBKVol.setText(texchangeRateInfo.getData().getTotal());
//                        mActivityBKMoney.setText(texchangeRateInfo.getData().getTrade_price());


        Gson gson = new Gson();
        FuturesInfo futuresInfo = gson.fromJson(result, FuturesInfo.class);
        String settle_anchor = futuresInfo.getData().getSettle_anchor();
        String total = futuresInfo.getData().getTicker().getTotal();
        String amount = futuresInfo.getData().getTicker().getAmount();
        double trade_price = futuresInfo.getData().getTicker().getTrade_price();
        double change_24h = futuresInfo.getData().getTicker().getChange_24h();
        String max_24h_price = futuresInfo.getData().getTicker().getMax_24h_price();
        String min_24h_price = futuresInfo.getData().getTicker().getMin_24h_price();
        double mark_price = futuresInfo.getData().getTicker().getMark_price();
        String price_float_num = futuresInfo.getData().getPrice_float_num();

        mActivityBKMoney.setText(Tools.round(trade_price, Integer.valueOf(price_float_num)).toString().trim());

        if (change_24h > 0) {
            mActivityBKRise.setTextColor(getResources().getColor(R.color.green));

        } else {
            mActivityBKRise.setTextColor(getResources().getColor(R.color.red));
        }

        if (old > mark_price) {
            mActivityBKMoney.setTextColor(getResources().getColor(R.color.red));

        } else if (old == mark_price) {
        } else {
            mActivityBKMoney.setTextColor(getResources().getColor(R.color.green));

        }

        old = mark_price;

        String trimamount = Tools.round(Double.valueOf(amount), 0).toString().trim();
        String trimatotal = Tools.round(Double.valueOf(total), Integer.valueOf(price_float_num)).toString().trim();

        mActivityBKRise.setText(Tools.round(Double.valueOf(change_24h) * 100, Integer.valueOf(price_float_num)).toString().trim() + "%");
        activity_kine_24.setText(trimamount + "\t" + "张" + "\t" + "\t" + "≈" + "\t" + trimatotal + "\t" + settle_anchor);
        mActivityBKHeight.setText(Tools.round(Double.valueOf(max_24h_price), Integer.valueOf(price_float_num)).toString().trim());
        mActivityBKLowest.setText(Tools.round(Double.valueOf(min_24h_price), Integer.valueOf(price_float_num)).toString().trim());
        String open_interest = futuresInfo.getData().getTicker().getOpen_interest();
        String open_interest_ev = futuresInfo.getData().getTicker().getOpen_interest_ev();

        String trim = Tools.round(Double.valueOf(open_interest_ev), Integer.valueOf(price_float_num)).toString().trim();
        mActivityLinCiCangLiang.setText(open_interest + "\t" + "张" + "\t" + "\t" + "≈" + "\t" + trim + "\t" + settle_anchor);

    }


    private Handler handler = new Handler() {

    };
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {

            if (isActivityShow) {
                geTexchangeRate();
                getListInfo();
//
//                if (times.equals("15")) {
//                    initInfo("15m");
//                } else if (times.equals("5")) {
//                    initInfo("5m");
//                } else if (times.equals("30")) {
//                    initInfo("30m");
//                } else if (times.equals("1h")) {
//                    initInfo("1h");
//
//                } else if (times.equals("1")) {
//                    initInfo("1m");
//                } else if (times.equals("4h")) {
//                    initInfo("4h");
//                } else if (times.equals("1d")) {
//
//                    initInfo("1d");
//                } else if (times.equals("1w")) {
//
//                    initInfo("1w");
//                }

                handler.postDelayed(this, 5000);
            } else {
                return;
            }


        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        isActivityShow = true;
        handler.postDelayed(runnable, 0);

    }

    @Override
    protected void onPause() {
        super.onPause();
//        Log.i("kwjehfuwihefweui2323232", "1");
        isActivityShow = false;
        OkGo.getInstance().cancelTag(this);

    }

    private void setKineData(String result) {
        Gson gson = new Gson();
        BtexInfo btexInfo = gson.fromJson(result, BtexInfo.class);
        List<List<String>> lists = btexInfo.getData().getLists();

        List<KData> dataList = new ArrayList<>();

        double openPrice;
        double closePrice;
        double maxPrice;
        double minPrice;
        double volume;
        long kinetime;


        if (lists.size() > 0) {

            for (int i = 0; i < lists.size(); i++) {

//            时间
                kinetime = Long.valueOf(lists.get(i).get(0));
//            开盘价
                openPrice = Double.valueOf(lists.get(i).get(1));
//            最高价
                maxPrice = Double.valueOf(lists.get(i).get(2));
//            最低价
                minPrice = Double.valueOf(lists.get(i).get(3));
//            收盘价
                closePrice = Double.valueOf(lists.get(i).get(4));
//            成交量
                volume = Double.valueOf(lists.get(i).get(5));
//            填充数据
                dataList.add(new KData(kinetime, openPrice, closePrice, maxPrice, minPrice, volume));
//            最后的成交价就是开盘价
                openPrice = closePrice;

            }

            if (size > 0) {

                mKineview.resetDataList(dataList);
            } else {

                mKineview.initKDataList(dataList);
            }

            mKineview.setDeputyPicShow(true);

            size++;


        }


    }


    private void getMxCcontracts(String type) {

        int num = (int) ((Math.random() * 9 + 1) * 100000);
        OkGo.<String>get(Config.GET_MX_CONTRACTS + "?rnd=" + String.valueOf(num)).tag(this).params("contract_id", type).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {

                Log.i("wkefwheufiwhe", response.body().toString());
                String result = response.body().toString();

                try {
                    JSONObject jsonObj = new JSONObject(result);
                    if (jsonObj.getString("code").equals("1")) {
                        Gson gson = new Gson();
                        FuturesInfo futuresInfo = gson.fromJson(result, FuturesInfo.class);
                        mPrice_float_num = futuresInfo.getData().getPrice_float_num();
                        mSa_float_num = futuresInfo.getData().getSa_float_num();
                        mContract_anchor = futuresInfo.getData().getQuote_anchor();
                        mActivityBKVol.setText(Tools.round(Double.valueOf(futuresInfo.getData().getTicker().getIndex_price()), Integer.valueOf(mPrice_float_num)).toString());
                        activity_k_heli.setText(Tools.round(Double.valueOf(futuresInfo.getData().getTicker().getMark_price()), Integer.valueOf(mPrice_float_num)).toString());
                        initViewPager();

                    } else {

                    }


                } catch (JSONException e) {
                    e.printStackTrace();

                }

            }
        });


//        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(this);
//        PreferencesCookieStore cookieStore = CookieTool.getCookieStore(this, sharedPreferences);
//        RequestParams params = new RequestParams();
//        params.addHeader("app-version", Config.VERSION);
//        params.addHeader("channel", MyApplication.mApp.getApplicationMetaData("CXD_CHANNEL_ID"));
//        params.addHeader("my-client", "android");
//        params.addQueryStringParameter("contract_id", type);
//
////        int num = (int) ((Math.random() * 9 + 1) * 100000);
//        new HttpUtils().configCookieStore(cookieStore).send(HttpRequest.HttpMethod.GET, Config.GET_MX_CONTRACTS + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                Log.i("mgfubvjsjhdjshdsjhdygu", responseInfo.result);
//
//                try {
//
//                    JSONObject jsonObj = new JSONObject(responseInfo.result);
//                    if (jsonObj.getString("code").equals("1")) {
//                        Gson gson = new Gson();
//                        FuturesInfo futuresInfo = gson.fromJson(responseInfo.result, FuturesInfo.class);
//                        mPrice_float_num = futuresInfo.getData().getPrice_float_num();
//                        mSa_float_num = futuresInfo.getData().getSa_float_num();
//                        mContract_anchor = futuresInfo.getData().getContract_anchor();
//                        mActivityBKVol.setText(Tools.round(Double.valueOf(futuresInfo.getData().getTicker().getIndex_price()), Integer.valueOf(mPrice_float_num)).toString());
//                        activity_k_heli.setText(Tools.round(Double.valueOf(futuresInfo.getData().getTicker().getMark_price()), Integer.valueOf(mPrice_float_num)).toString());
//
//                        initViewPager();
//
//                    } else {
//
//                    }
//
//
//                } catch (JSONException e) {
//                    e.printStackTrace();
//
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//
//            }
//
//        });


    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);

    }


    @OnClick(R.id.activity_futures_full)
    public void onViewClicked() {

        startActivity(new Intent(this, KLineFullActivity.class).putExtra("pair", "").putExtra("contract_id", mContract_id));
    }
}
